package org.hrhr74.mapper;

import org.apache.ibatis.annotations.*;
import org.hrhr74.entity.User;

@Mapper
public interface UserMapper {
    @Select("select * from user where phone=#{phone}")
    User getByPhone(@Param("phone") String phone);

    @Insert("insert into user(username,phone) values (#{username},#{phone})")
    void saveUserByPhone(User user);
    @Update({
            "<script>",
            "UPDATE user",
            "  <set>",
            "    <if test='username != null'>username = #{username},</if>",
            "    <if test='password != null'>password = #{password},</if>",
            "  </set>",
            "WHERE account = #{account}",
            "</script>"
    })
    void editUser(User user);

    @Select("select  * from user where account=#{account}")
    User getUserByAccount(@Param("account") Long account);

    @Update("update user set phone = #{phone} where account = #{account}")
    void updatePhone(@Param("phone") String phone, @Param("account") Long account);
}
